package org.shangma.service.impl;

import io.seata.core.context.RootContext;
import org.shangma.common.Order;
import org.shangma.mapper.OrderMapper;
import org.shangma.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderMapper orderMapper;

    @Override
    public void addOrder(Order order) {
        System.out.println("是否在全局事务中：" + RootContext.inGlobalTransaction());
        System.out.println("事务id: " + RootContext.getXID());
        System.out.println("事务类型: " + RootContext.getBranchType());

        if(order.getId()==null){
            order.setId(new Long(System.nanoTime()).intValue());
        }
        orderMapper.addOrder(order);

    }
}
